<template>
  <div class="education-page h100 flex flex-column">
    <div class="edcation-top">
      <div class="logos flex flex-wrap" v-if="currentDept.logo || currentDept.hospitalLogo">
        <img :src="currentDept.hospitalLogo">
        <img :src="currentDept.logo">
      </div>
      <div>{{ currentDept.hospitalName }}  {{ currentDept.departmentName }}</div>

      <div class="flex"> 
        <router-link to="/search" class="flex1">
          <van-search
            disabled
            class="xlt-search"
            shape="round"
            background="transparent"
            placeholder="搜索文章"
          />
        </router-link>
        <div class="flex1 outer-article">
          <router-link to="/choose-dept" class="outer-btn flex flex-center">
            查看其他科室文章 <van-icon name="arrow" size="18px" />
          </router-link>
        </div>
      </div>
    </div>

    <div class="edcation-main flex1" v-if="isLoad && classifyList?.length">
      <div class="edcation-main-list flex flex-wrap">
        <template
          v-for="(item, index) in classifyList"
          :key="index"
        >
          <div
            class="disease-tag flex"
            :style="tagStyle(index)"
            @click="onTagClick(item,currentDept.departmentId)"
          >
            <img
              v-if="item.imgUrl && !item.isHide"
              :src="item.imgUrl"
              class="disease-tag-img"
              v-checkImg="item"
            >
            <div class="disease-tag-content" v-else>
              {{ item.articleCategoryName }}
            </div>
          </div>
        </template>
      </div>
    </div>

    <div class="edcation-main bg-white flex1" v-if="isLoad && !classifyList?.length">
      <Article />
    </div>
  </div>
</template>

<script>
import { ref, watch } from 'vue';
import { useCurrentDeptInfo } from '@/hooks/store';
import Article from '../article/components/Article';
import { useTagBackground, useClassify } from './useEducation';
export default {
  components: {
    Article
  },
  setup() {
    const { tagStyle } = useTagBackground();
    const currentDept = useCurrentDeptInfo();

    const { onTagClick, getClassify, isLoad } = useClassify();

    const classifyList = ref([]);

    watch(
      () => currentDept.value,
      async () => {
        if (currentDept.value.departmentId) {
          classifyList.value = await getClassify({
            departmentId: currentDept.value.departmentId,
            categoryId: 0
          });
        }
      },
      {
        immediate: true
      }
    );

    return {
      tagStyle,
      classifyList,
      onTagClick,
      currentDept,
      isLoad
    };
  }
};
</script>

<style lang="scss" scoped>
.education-page {
  background-image: linear-gradient(180deg, #bef0ee 0%, #f5fffe 37%, #bff0ee 100%);
}

.logos {
  margin-bottom: 15px;
  img {
    margin-bottom: 10px;
    margin-right: 40px;
    display: block;
    height: 52px;
  }
}

.outer-article {
  padding: 10px 0;
  margin-left: 22px;
  .outer-btn {
    background: #f7f8fa;
    border-radius: 36px;
    border: 2px solid #efefef;
    font-size: 30px;
    font-weight: 500;
    color: #27cdc5;
    height: 100%;
    text-align: center;
  }
}

.edcation-top {
  padding: 24px 32px 30px;
  font-size: 36px;
  font-weight: 500;
  color: #373d52;
}

.edcation-main {
  padding: 0 32px;
  overflow-y: auto;
  background: url('@/assets/images/h-bg.png') no-repeat left bottom / 750px 618px;
  .scrolly {
    overflow-y: auto;
  }

  .disease-tag {
    padding: 0 28px 47px 38px;
    border-radius: 16px;
    width: 47%;
    height: 226px;
    margin-bottom: 24px;
    font-size: 32px;
    font-weight: 500;
    color: #373d52;
    line-height: 44px;
    align-items: center;
    position: relative;
    background-repeat: no-repeat;
    background-size: cover;
    overflow: hidden;
    &:nth-of-type(2n) {
      margin-left: 6%;
    }

    &-img {
      width: 100%;
      position: absolute;
      top: 0;
      left: 0;
      object-fit: cover;
    }

    &-content {
      max-height: 132px;
      overflow: hidden;
    }
  }
}
</style>